﻿Imports System.ComponentModel
Imports NUnit.Framework
Imports ValidationFramework

Namespace BusinessBaseClasses
    Public Class NotifyBaseLambdaExample
#Region "Example"
        Public Class Person
            Inherits NotifyBase
#Region "Fields"

            Private _firstName As String
            Private _lastName As String
            Private _emailAddress As String

#End Region

#Region "Properties"

            Public Property FirstName() As String
                Get
                    Return _firstName
                End Get
                Set(ByVal value As String)
                    If _firstName <> value Then
                        _firstName = value
                        NotifyPropertyChanged(Function() FirstName)
                    End If
                End Set
            End Property
            Public Property LastName() As String
                Get
                    Return _lastName
                End Get
                Set(ByVal value As String)
                    If _lastName <> value Then
                        _lastName = value
                        NotifyPropertyChanged(Function() LastName)
                    End If
                End Set
            End Property
            Public Property EmailAddress() As String
                Get
                    Return _emailAddress
                End Get
                Set(ByVal value As String)
                    If _emailAddress <> value Then
                        _emailAddress = value
                        NotifyPropertyChanged(Function() EmailAddress)
                    End If
                End Set
            End Property
#End Region
        End Class

        <TestFixture()> _
        Public Class ExampleUsage
            Private firstNameEventFired As Boolean

            <Test()> _
            Public Sub RunEvent()
                Dim _person As New Person()

                ' Attach to PropertyChanged so we are notified 
                AddHandler _person.PropertyChanged, AddressOf person_PropertyChanged

                ' Set FirstName and hence firing the event
                _person.FirstName = "John"

                ' Since the event has fired the firstNameEventFired flag will be true;
                Assert.IsTrue(firstNameEventFired)
            End Sub


            Private Sub person_PropertyChanged(ByVal sender As Object, ByVal e As PropertyChangedEventArgs)
                firstNameEventFired = True
            End Sub
        End Class
#End Region
    End Class
End Namespace